package com.smile67.config;


import com.smile67.common.properties.AliOssProperties;
import com.smile67.common.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * OSS配置类：将AliOssUtil配置成为一个bean
 *
 * @author smile67
 * @version 1.0
 * @projectName ag_ai_ms
 * @package com.smile67.config;
 * @className OssConfiguration
 * @date 2023/7/14 15:14
 */
@Configuration
@Slf4j
public class OssConfiguration {

    @Bean
    @ConditionalOnMissingBean//当这个bean没有的时候才创建声明
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties) {
        log.info("开始创建阿里云文件上传工具类对象,注入的属性为：{}",aliOssProperties);
        return new AliOssUtil(
                aliOssProperties.getBucketName(),
                aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret()
        );
    }
}
